// /* global Vue */
import messager from 'common/messager'
import { DEFAULT_ERROR_MSG } from 'common/consts'
import systemLogout from 'common/system-logout'

export const errorPopMsg = {
  showTimeoutErrConfrim(errorObj) {
    messager.showAlert('warning', errorObj.message || DEFAULT_ERROR_MSG, '提示', () => {
      systemLogout()
    })
  }
}

export const errorCodeMatch = {
  '-1'(resData) {
    const errorObj = { code: resData.code, message: resData.detailMessage || resData.message }
    errorPopMsg.showTimeoutErrConfrim(errorObj)
    throw (errorObj)
  },

  '100014'(resData) {
    const errorObj = { retCode: resData.code, message: resData.message }
    errorPopMsg.showTimeoutErrConfrim(errorObj)
    throw (errorObj)
  },

  '401'(resData) {
    const errorObj = { retCode: resData.code, message: resData.message || '登录已失效，请重新登录' }
    errorPopMsg.showTimeoutErrConfrim(errorObj)
    throw (errorObj)
  },

  '500'(resData) {
    const errorObj = { retCode: resData.code, message: resData.message || resData.retDesc }
    throw (errorObj)
  }
}
